package pers.cj.pdos.controller.other;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pers.cj.pdos.controller.base.BaseController;
import pers.cj.pdos.controller.entity.ResponseData;
import pers.cj.pdos.entity.Company;
import pers.cj.pdos.service.*;
import pers.cj.pdos.utils.PdosUtils;
import pers.cj.pdos.utils.Utils;
import pers.cj.pdos.vo.UserVo;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
public class HomeController extends BaseController {
    @Autowired
    IGoodsHouseWarnService goodsHouseWarnService;
    @Autowired
    IGoodsService goodsService;
    @Autowired
    ISaleOrderService saleOrderService;
    @Autowired
    IInGoodsOrderService inGoodsOrderService;
    @Autowired
    IPayWaitService payWaitService;
    @Autowired
    IArrearsWaitService arrearsWaitService;
    @Autowired
    IHouseWaitInService houseWaitInService;
    @Autowired
    IHouseWaitOutService houseWaitOutService;

    @RequestMapping("/home")
    public String home(Model model){
        model.addAttribute("userVo",getLoginUserVo());
        return "home";
    }

    @RequestMapping("welcome")
    public String welcome() {
        return "welcome";
    }

    /**
     * 获取欢迎页所需要的的数据
     * @return
     */
    @ResponseBody
    @RequestMapping("/welcome/data")
    public ResponseData welcomeData(){
        Company company = getCompany();
        UserVo userVo = getLoginUserVo();
        Map<String,Long> map = new HashMap<>();

        Long maxGoodsNumber = goodsHouseWarnService.countMaxNumber(company.getId());
        map.put("maxGoodsNumber",maxGoodsNumber);
        Long minGoodsNumber = goodsHouseWarnService.countMinNumber(company.getId());
        map.put("minGoodsNumber",minGoodsNumber);
        Long goodsNUmber = goodsService.count(company.getId(),1,null,null,null,null,null,null,null,null);
        map.put("goodsNumber",goodsNUmber);

        Long saleOrderNumber = saleOrderService.count(company.getId(), false,null,null,null,null,null,null,
                null,null,null,null, PdosUtils.getViewOrderStoreId(userVo,null),PdosUtils.getViewOrderUserId(userVo,null),
                null,null,null,null);
        map.put("saleOrderNumber",saleOrderNumber);

        Long inGoodsOrderNumber = inGoodsOrderService.count(company.getId(), false,null,null,null,null,null,null,null,
                null,PdosUtils.getViewOrderStoreId(userVo,null),PdosUtils.getViewOrderUserId(userVo,null),null,null,null,null);
        map.put("inGoodsOrderNumber",inGoodsOrderNumber);

        Long payWaitNumber = payWaitService.count(company.getId(),PdosUtils.getViewOtherStoreId(userVo,null),null,true,null,null);
        map.put("payWaitNumber",payWaitNumber);

        Long arrearsWaitNumber = arrearsWaitService.count(company.getId(),PdosUtils.getViewOtherStoreId(userVo,null),null,true,null,null);
        map.put("arrearsWaitNumber",arrearsWaitNumber);

        Long houseWaitOutNumber = houseWaitOutService.count(company.getId(), null, null, null, null, null,
                null, null, null, null, null, PdosUtils.getViewOrderStoreId(userVo,null),PdosUtils.getViewOrderUserId(userVo,null), null, null,null, null);
        map.put("houseWaitOutNumber",houseWaitOutNumber);

        Long houseWaitInNumber = houseWaitInService.count(company.getId(), null, null, null, null, null,
                null, null, null, null, null, PdosUtils.getViewOrderStoreId(userVo,null),PdosUtils.getViewOrderUserId(userVo,null), null,null, null, null);
        map.put("houseWaitInNumber",houseWaitInNumber);
        return ResponseData.success(map);
    }
}
